package com.example.common.model

import com.example.network.HttpInterceptorType
import com.example.common.api.BaseApiServer
import com.example.network.HttpManager

abstract class BaseRepository<T:BaseApiServer>{

    private var tokenApiServer:T?=null
    private var signApiServer:T?=null
    private var uploadApiServer:T?=null
    private var commonApiServer:T?=null

    fun <T> createApiServer(clazz: Class<T>, type: HttpInterceptorType): T {
        if (HttpInterceptorType.TOKEN == type){
            if (tokenApiServer == null){
                tokenApiServer = HttpManager.createApiServer(clazz, type)
            }
            return tokenApiServer as T
        }

        if (HttpInterceptorType.SIGN == type){
            if (signApiServer == null){
                signApiServer = HttpManager.createApiServer(clazz, type)
            }
            return signApiServer as T
        }

        if (HttpInterceptorType.UPLOAD == type){
            if (uploadApiServer == null){
                uploadApiServer = HttpManager.createApiServer(clazz, type)
            }
            return uploadApiServer as T
        }

        if (HttpInterceptorType.INTERCEPTOR == type){
            if (commonApiServer == null){
                commonApiServer = HttpManager.createApiServer(clazz, type)
            }
            return commonApiServer as T
        }

        return HttpManager.createApiServer(clazz, type) as T
    }








}